package ast;

import java.util.ArrayList;

import scanner.Token;

public abstract class ASTNode {
    protected Token data;

    protected ArrayList<ASTNode> children;
    
    protected ASTNode(Token data)
    {
        this.data = data;
        children = new ArrayList<ASTNode>();
    }
    
    protected ASTNode()
    {
        this(null);
    }
    
    public Token getData() {
        return data;
    }

    public void setData(Token data) {
        this.data = data;
    }

    public ArrayList<ASTNode> getChildren() {
        return children;
    }

    public void setChildren(ArrayList<ASTNode> children) {
        this.children = children;
    }

    public ASTNode addChild(ASTNode node) {
        this.children.add(node);

        return node;
    }

    public abstract String toString(int depth);

    /**
     * Helper function that returns the Indentation for the depth.  Used for printing out the AST
     * @param depth the depth of the node.
     * @return a string '"--" * depth'...so depth=3 will return "------"
     */
    public static String indent(int depth) {
        // create indentation
        String indent = "";
        for (int i = 0; i < depth; i++) {
            indent += "----";
        } //TODO if only we could multiply string! =)
        return "\n" + indent;
    }

    public abstract void run(Evaluation input) throws Exception;
}
